package com.example.demo.service.Impl;

import com.example.demo.common.utills.CommonResult;
import com.example.demo.common.utills.FileUtil;
import com.example.demo.common.utills.TimeUtil;
import com.example.demo.mapper.DataReportsMapper;
import com.example.demo.mapper.SharedPlatformMapper;
import com.example.demo.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Service
public class FileServiceImpl implements FileService {
    @Resource
    DataReportsMapper dataReportsMapper;

    @Resource
    SharedPlatformMapper sharedPlatformMapper;

    @Override
    public CommonResult uploadFile(MultipartFile multipartFile, String name,int uid) {
        String path= FileUtil.uploadFile(multipartFile, name);
        String time = TimeUtil.SimpleTime();
        if(path!=null){
            if(name.startsWith("报表名称")){
                dataReportsMapper.insertDataReportsFile(name,time,uid,path);
            }
            else{
                sharedPlatformMapper.insertSharedPlatformFile(name,time,uid,path);
            }
            return new CommonResult(200,"上传成功");
        }
        return new CommonResult(500,"上传失败");
    }
}
